package com.example.coffeeseller_2.model.helper.view_helper;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.coffeeseller_2.R;
import com.example.coffeeseller_2.model.helper.TradeAnimManager;

/**
 * Created by WH on 2018/8/12.
 */

public class CheckTipBeforeMakeViewHelper {

    private View view;
    private Context context;
    private TextView textView;
    private Handler handler;
    ImageView loading_1;
    ImageView loading_2;
    ImageView loading_3;
    ImageView loading_4;

    public CheckTipBeforeMakeViewHelper(Context context) {
        this.context = context;
        this.handler = new Handler();
        view = LayoutInflater.from(context).inflate(R.layout.include_loading_tip, null, false);
        textView = (TextView) view.findViewById(R.id.errTip);
        loading_1 = (ImageView) view.findViewById(R.id.loading_1);
        loading_2 = (ImageView) view.findViewById(R.id.loading_2);
        loading_3 = (ImageView) view.findViewById(R.id.loading_3);
        loading_4 = (ImageView) view.findViewById(R.id.loading_4);
    }

    public void startAnim() {

        if (loading_1==null&&loading_2==null&&loading_3==null&&loading_4==null){
            return;
        }

        TradeAnimManager.startWaitRotateAnim(loading_1, 0, 360);
        TradeAnimManager.startWaitRotateAnim(loading_2, 0, 360);
        TradeAnimManager.startWaitRotateAnim(loading_3, 0, 360);
        TradeAnimManager.startWaitRotateAnim(loading_4, 0, -360);
    }

    private void clearAnim() {

        if (loading_1 != null) loading_1.clearAnimation();
        if (loading_2 != null) loading_2.clearAnimation();
        if (loading_3 != null) loading_3.clearAnimation();
        if (loading_4 != null) loading_4.clearAnimation();
    }
    public void clear(){
        clearAnim();
    }


    public void setText(final String text) {
        handler.removeCallbacksAndMessages(null);
        handler.post(new Runnable() {
            @Override
            public void run() {
                textView.setText(text);

            }
        });
    }

    public View getView() {

        return view;
    }
}
